import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei'] # 在matplotlib中设置字体为SimHei黑体
plt.rcParams['axes.unicode_minus'] = False# 解决matplotlib坐标轴负号‘-’显示为方块问题
df1=pd.read_csv(r"C:\Users\gcc\Desktop\nanjingf.csv").drop_duplicates()#爬取的数据可能有重复行
df2=pd.read_csv(r"C:\Users\gcc\Desktop\suzhouf.csv").drop_duplicates()
df3= pd.read_csv(r"C:\Users\gcc\Desktop\wuxif.csv").drop_duplicates()

def creatSeries(dic):
    index=dic['门店名称'].values
    data=dic['评论数'].values
    se=pd.Series(data=data,index=index)
    return se
def morebar(se1,se2,se3):#绘制三大城市的餐饮销量并列条图
    plt.figure(figsize=(20,10))
    x=np.arange(5)
    y1=se1.values.astype(np.int)
    y2=se2.values.astype(np.int)
    y3=se3.values.astype(np.int)
    tick_label=['top1','top2','top3','top4','top5']
    bar_width=0.3
    plt.bar(x,y1,bar_width,color='salmon',align='center',label='南京')
    plt.bar(x+bar_width, y2, bar_width, color='orchid', align='center', label='苏州')
    plt.bar(x+2*bar_width, y3, bar_width, color='orange', align='center', label='无锡')
    plt.legend()
    plt.xticks(x+bar_width/2,tick_label)
    plt.xlabel("餐饮门店排名")
    plt.ylabel("顾客评论数")
    plt.show()
def function():#z先按照评论人数排序排序，然后选择每个城市前五名的评论数做成并列条图
    dic1=df1.sort_values(by='评论数',ascending=False)
    dic2 = df2.sort_values(by='评论数', ascending=False)
    dic3 = df3.sort_values(by='评论数', ascending=False)
    se1=creatSeries(dic1)
    se2=creatSeries(dic2)
    se3=creatSeries(dic3)
    se1=se1[:5]
    se2=se2[:5]
    se3=se3[:5]
    print(se1)
    print(se2)
    print(se3)
    morebar(se1,se2,se3)

function()

